package com.rchat.pocmini.util;

import android.media.AudioManager;
import android.media.SoundPool;

import com.aso.common.utils.Utils;
import com.rchat.pocmini.R;

import java.util.HashMap;

/**
 * @Description ：
 * @Author itsdf07
 * @Time 2018/1/15
 */

public class SoundPoolUtils {
    public interface ISoundPoolCallback {
        void onComplete();
    }

    public static final int KEY_SOUND_A1 = 1;
    public static final int KEY_SOUND_A2 = 2;
    private ISoundPoolCallback mSoundPoolCallback;
    private static SoundPoolUtils instance;
    private SoundPool mSoundPool;
    private HashMap<Integer, Integer> mSoundPoolMap;

    public static SoundPoolUtils getInstance() {

        if (instance == null) {
            instance = new SoundPoolUtils();
        }
        return instance;
    }

    public SoundPoolUtils() {
        mSoundPool = new SoundPool(1, AudioManager.STREAM_ALARM, 0);
        mSoundPoolMap = new HashMap<>();
        mSoundPoolMap.put(KEY_SOUND_A1, mSoundPool.load(Utils.getApplication(), R.raw.sound_media_me_on, 1));
        mSoundPoolMap.put(KEY_SOUND_A2, mSoundPool.load(Utils.getApplication(), R.raw.sound_media_me_off, 1));

    }

    public void onPlay(int key_sound, SoundPool.OnLoadCompleteListener listener) {
        mSoundPool.setOnLoadCompleteListener(listener);
        mSoundPool.play(mSoundPoolMap.get(key_sound), 1, 1, 0, 0, 1);
    }
}
